import {
  createRouter,
  BeforeEachResult
} from '@gowiny/uni-router'
import PAGE_DATA from '@/pages.json';
import store from '@/store/index.js'
const router = createRouter({
  pageData: PAGE_DATA
})
router.beforeEach((to, from) => {
  if (JSON.stringify(from) !== JSON.stringify(to)) { // 避免一开始多次触发
    if(to.path==="/pages/login/login"){
      if(store.state.user.cookie){
        uni.showToast({
          title:"您已登录，请勿重复登录"
        })
        return {
          to:{
            path:'/pages/my/my'
          },
          navType:'pushTab'//跳转方式
        }
      }
      if(from){
        store.commit('user/setRedirect',from.fullPath)
      }
      else {
        // 啥都不干
        
      }
    }
  }
})
export default router
